/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import entity.LeaveForm;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Kien Chinh
 */
public class ModelTableApproveLeave extends AbstractTableModel{
    private static final int STT = 0;
    private static final int EMPLOYEENAME = 1;
    private static final int LEAVETYPE = 2;
    private static final int STARTDATE = 3;
    private static final int ENDDATE = 4;
    private static final int RESON = 5;
    private String[] columnName = {"No.","Name","Type","Start leave","End leave","Reson"}; 
    
    ArrayList<LeaveForm> list;

    public ModelTableApproveLeave(ArrayList<LeaveForm> list) {
        this.list = list;
    }
    
    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return columnName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        LeaveForm form = list.get(rowIndex);
        switch(columnIndex){
            case EMPLOYEENAME:
                return form.getEmployee().getFullName();
            case LEAVETYPE: 
                return form.getListLeave().get(0).getType().getName();
            case STARTDATE:
                return form.getListLeave().get(0).getStartLeave();
            case ENDDATE:
                return form.getListLeave().get(form.getListLeave().size()-1).getFinishLeave();
            case RESON :
                return form.getListLeave().get(0).getReson();
            case STT:
                return rowIndex+1;
            default :
                return new Object();
        }
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnName[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
}
